package com.learn.initbean.lifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author daify
 * @date 2019-03-23 15:54
 */
public class LifeCycleBeanTest implements
        BeanNameAware, //BeanName 的 Aware
        BeanFactoryAware, //BeanFactory 的 Aware
        BeanClassLoaderAware,//BeanClassLoader 的 Aware
        BeanPostProcessor,//后置
        InitializingBean,//初始化方法的
        DisposableBean {//销毁的

    private String name;

    public LifeCycleBeanTest(){ // 构造方法
        System.out.println("构造函数调用...");
    }

    public void display(){
        System.out.println("方法调用...");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("setBeanClassLoader 被调用...");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("setBeanFactory 被调用...");

    }

    @Override
    public void setBeanName(String s) {
        System.out.println("setBeanName 被调用...");

    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("BeanPostProcessor postProcessBeforeInitialization 被调用...");
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("BeanPostProcessor postProcessAfterInitialization 被调用...");
        return bean;
    }


    @Override
    public void destroy() throws Exception {
        System.out.println("DisposableBean destroy 被调动...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("InitializingBean afterPropertiesSet 被调动...");
    }

    public void initMethod(){
        System.out.println("init-method 被调用...");
    }

    public void destroyMethdo(){
        System.out.println("destroy-method 被调用...");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        System.out.println("属性注入....");
        this.name = name;
    }
}
